
export interface IHttpResponse<T = any> {
    code: number;
    msg: string;
    data: T;
}


export default class HttpClient {

    public static async get<T>(url: string, queryParams?: Record<string, any>, headers?: Record<string, string>): Promise<T> {
        let res: IHttpResponse = null;
        try {
            res = await Guyu.Http.get<IHttpResponse>(url, queryParams, headers);
        } catch (e) {
            return Promise.reject(e);
        }
        if (res.code !== 0) {
            return Promise.reject(res);
        }
        return Promise.resolve(res.data);
    }

    public static async post<T>(url: string, data: object, headers?: Record<string, string>): Promise<T> {
        let res: IHttpResponse = null;
        try {
            res = await Guyu.Http.post<IHttpResponse>(url, data, headers);
        } catch (e) {
            return Promise.reject(e);
        }
        if (res.code !== 0) {
            return Promise.reject(res);
        }
        return Promise.resolve(res.data);
    }
}